//
//  DoctorPulseViewController.m
//  JiuLe
//
//  Created by 黄鑫 on 2016/11/17.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "DoctorPulseViewController.h"

@interface DoctorPulseViewController ()<UIWebViewDelegate>
@property (strong, nonatomic) UIWebView *webViewMain;
@property (strong, nonatomic) NSString *homeURL;
@property (strong, nonatomic) NSString *otherURL;

@end

@implementation DoctorPulseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showNavgationWithLeftItemWithTitle:@"返回" twoItemWithtitle:@"╳"];
    _webViewMain = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    _webViewMain.delegate = self;
    [self.view addSubview:_webViewMain];
    UIActivityIndicatorView *testActivityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    testActivityIndicator.center = CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2-64);
    [testActivityIndicator startAnimating];
    testActivityIndicator.tag = 12;
    [self.view addSubview:testActivityIndicator];
    [self.view bringSubviewToFront:testActivityIndicator];
        self.title = @"医脉";
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
                                        initWithURL:[NSURL URLWithString:@"http://www.jiuletech.com:8088/index.php/Yimai/index"]
                                        cachePolicy:NSURLRequestUseProtocolCachePolicy
                                        timeoutInterval:15.f];
        [_webViewMain loadRequest:request];

}

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setHidesBottomBarWhenPushed:YES];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self.navigationController setHidesBottomBarWhenPushed:NO];
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"webViewDidStartLoad");
}


- (void)webViewDidFinishLoad:(UIWebView *)web{
    UIActivityIndicatorView *testActivityIndicator = [self.view viewWithTag:12];
    [testActivityIndicator removeFromSuperview];
    if ([_homeURL isEqualToString:@""] || _homeURL == nil) {
        _homeURL =  _webViewMain.request.URL.absoluteString;
        NSLog(@"%@",_homeURL);
    }
    _otherURL =  _webViewMain.request.URL.absoluteString;
}

- (void)webView:(UIWebView*)webView  DidFailLoadWithError:(NSError*)error{
    NSLog(@"DidFailLoadWithError");
}

- (void)backTo{
    if ([_homeURL isEqualToString:_otherURL]) {
        if (self.navigationController) {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        [_webViewMain goBack];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
